<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .box {
        width: 500px;
        height: 300px;
        /* border: 1px solid #ccc; */
        margin: 50px auto;
      }

      span {
        width: 80px;
        height: 30px;
        border: 1px solid #ccc;
        display: inline-block;
        text-align: center;
        line-height: 30px;
      }

      .body {
        margin-top: 5px;
        width: 450px;
        border: 1px solid #ccc;
        height: 250px;
        background: #eee;
      }

      .current {
        color: red;
        background: #555;
      }

      .body div {
        display: none;
        text-align: center;
        line-height: 250px;
      }

      .body .active {
        display: block;
      }
    </style>
  </head>
  <body>
    <div class="box">
      <div class="header">
        <span class="current">关注</span>
        <span class="">推荐</span>
        <span class="">热点</span>
        <span class="">本地</span>
        <span class="">段子</span>
      </div>
      <div class="body">
        <div class="active">关注：双色球中奖了没？</div>
        <div class="">推荐：双12的单身狗不过节买什么东西？</div>
        <div class="">热点：给美国榜一点点关注。</div>
        <div class="">本地：昨晚广州警方开展了大规模的扫黄打非活动。</div>
        <div class="">段子：段友出征，寸草不生。</div>
      </div>
    </div>
    <script>
      var Ospan = document.getElementsByTagName("span");
      var divs = document.querySelector(".body").children;
      for (var i = 0; i < Ospan.length; i++) {
        Ospan[i].index = i;
        Ospan[i].onclick = function () {
          for (var j = 0; j < Ospan.length; j++) {
            Ospan[j].className = "";
          }
          this.className = "current";

          for(var k=0;k<divs.length;k++){
            divs[k].className="";

            divs[this.index].className="active";
        }
        };
        
      }
    </script>
  </body>
</html>
